package com.zmn.plat.admin.controller.channel.workorder.video;

import com.zmn.plat.common.dictionary.ChannelWorkOrderPictureTypeEnum;
import com.zmn.plat.model.entity.channel.Channel;
import com.zmn.plat.model.entity.channel.workorder.video.ChannelWorkOrderVideo;
import com.zmn.plat.model.entity.channel.workorder.video.ChannelWorkOrderVideoQuery;
import com.zmn.plat.model.entity.servcategory.ServCategory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 类描述：渠道-工单视频
 *
 * @author yangshuangping
 * @since 2021/06/07 14:00
 */
@Controller
@RequestMapping("/channel/workorder/video/")
public class ChannelWorkOrderVideoListController extends ChannelWorkOrderVideoBaseController {
    @RequestMapping("list")
    @RequiresPermissions("/channel/workorder/video/list.action")
    public ModelAndView listPage(@ModelAttribute ChannelWorkOrderVideoQuery query) {

        // 根据渠道ID获取工单视频,渠道信息
        List<ChannelWorkOrderVideo> items = channelVideoService.listPageByQuery(query);
        Channel channel = channelService.findByKey(query.getChannelId());

        // 前端视图
        ModelAndView mav = new ModelAndView("channel/workorder/video/list");
        mav.addObject("items", items);
        mav.addObject("obj", channel);
        mav.addObject("flag", 17);
        mav.addObject("query", query);
        return mav;
    }

    /**
     * 跳转到新增或则修改界面
     *
     * @param channelId 渠道ID
     * @param id        工单视频ID
     * @return 视图
     */
    @RequestMapping("addEditView")
    @RequiresPermissions("/channel/workorder/video/addEditView.action")
    public ModelAndView detail(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId
            , @RequestParam(value = "id", defaultValue = "0") Integer id) {

        ChannelWorkOrderVideo video;
        if (id == 0) {
            video = new ChannelWorkOrderVideo();
            video.setVideoId(0);
            video.setChannelId(channelId);
        } else {
            video = channelVideoService.findByKey(id);
        }
        // 服务分类
        ServCategory querySC = new ServCategory();
        List<ServCategory> servCategories = servCategoryService.listByQuery(querySC);

        ModelAndView mav = new ModelAndView("channel/workorder/video/detail");
        mav.addObject("obj", video);
        mav.addObject("pictureTypes", ChannelWorkOrderPictureTypeEnum.list());
        mav.addObject("servCategories", servCategories);

        return mav;
    }
}
